import Vue from "vue";
import VueRouter from "vue-router";
import HomeView from "../views/HomeView.vue";

//获取原型对象上的push函数
const originalPush = VueRouter.prototype.push;
//修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "home",
    component: HomeView,
  },
  {
    path: "/about",
    name: "about",
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/AboutView.vue"),
  },
  {
    path: "/main",
    name: "main",
    component: () => import("../views/MainView.vue"),
  },
  {
    path: "/help",
    name: "help",
    component: () => import("../views/Help.vue"),
  },
  {
    path: "/login",
    name: "login",
    component: () => import("../views/account/Login.vue"),
  },
  {
    path: "/register",
    name: "register",
    component: () => import("../views/account/Register.vue"),
  },
  {
    path: "/cart",
    name: "cart",
    component: () => import("../views/cart/Cart.vue"),
  },
  {
    path: "/order",
    name: "order",
    component: () => import("../views/Order.vue"),
  },
  {
    path: "/category/:type",
    name: "category",
    component: () => import("..//views//catalog//Category.vue"),
  },
  {
    path: "/product/:type",
    name: "product",
    component: () => import("..//views//catalog//Product.vue"),
  },
  {
    path: "/item/:type",
    name: "item",
    component: () => import("..//views//catalog//Item.vue"),
  },
  {
    path: "/search/:type",
    name: "search",
    component: () => import("..//views//catalog//Search.vue"),
  },
  {
    path: "/myaccount",
    name: "myaccount",
    component: () => import("..//views//account//MyAccount.vue"),
  },
  {
    path: "/pay/:type",
    name: "pay",
    component: () => import("..//views//Pay.vue"),
  },
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});

export default router;
